package com.atguigu.springcloud.order.controller;

import com.atguigu.springcloud.order.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lenovo
 * @version 1.0
 * @date 2020/11/12 9:58
 */
@RestController
@Slf4j
@RequestMapping("consumer")
public class OrderFeignHystrixController {

    @Autowired
    private PaymentHystrixService paymentHystrixService;

    @GetMapping("payment/hystrix/ok/{id}")
    public String getInfoOk(@PathVariable("id") Long id) {
        return paymentHystrixService.getInfoOk(id);
    }


//    @HystrixCommand(fallbackMethod = "getInfoTimeoutHandler" , commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds" , value = "10000")
//    })
    @GetMapping("payment/hystrix/timeout/{id}")
    public String getInfoTimeout(@PathVariable("id") Long id) {
        String infoTimeout = paymentHystrixService.getInfoTimeout(id);
        log.info(infoTimeout);
        return infoTimeout;
    }


    public String getInfoTimeoutHandler(Long id){
        String s = "消费者80 consumer，这里表示自身的Hystrix服务熔断/服务降级 timeout id=[" + id + "] ，系统异常或者运行报错，超时了 /(ㄒoㄒ)/~~";
        log.error(s);
        return s;
    }

}
